import { createStore } from 'vuex'

// 创建vuex的根部对象
let store = createStore({
  state: { //设计的公共状态
    count: 1
  },
  mutations: {
    setCount (state, num) { //同步改变count的方法
      state.count += num
    }
  },
  actions: {
    actCount ({ commit }, num) { //异步改变state的方法  
      commit("setCount", num)
    }
  },
  getters: { //计算属性
    doubleCount (state) {
      return state.count * 2
    }
  },
  modules: {}
})
export default store